package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.base.BaseModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.ErrorCorrectionContarct;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Description:
 * Created by FHW
 * on 2017/5/11
 */

public class ErrorCorrectionPresenter extends BasePresenter implements ErrorCorrectionContarct.Presenter {

    private ErrorCorrectionContarct.View view;
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;


    @Inject
    public ErrorCorrectionPresenter(ErrorCorrectionContarct.View view) {
        this.view = view;
    }

    @Override
    public void submitError(String SalesID, String ProductLoansID, String ErrorContent) {
        rsaJsonUtil.put("SalesID", SalesID);
        rsaJsonUtil.put("ProductLoansID", ProductLoansID);
        rsaJsonUtil.put("ErrorContent", ErrorContent);
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.submitError(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<BaseModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpExcUtil.printError(e);
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onNext(BaseModel baseModel) {
                        view.loadSucError(baseModel);
                    }
                });
    }
}
